package robots;

import java.io.IOException;
import java.util.HashMap;

import junit.framework.Assert;

import maze.Coordinate;
import maze.Direction;
import maze.Maze;

import org.junit.Test;

import pacman.Game;
import robots.analyser.DistanceToWall;
import simulation.ColorMap;
import simulation.Simulator;
import static org.junit.Assert.*;

public class OwnGhostTest {

	@Test
	public void testWriteWalls() throws IOException {
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		Game game = new Game();
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator sim = new Simulator(maze,colorMap);
		OwnGhost ghost = new VirtualGhost(game, "jos", sim);
		HashMap<Direction, DistanceToWall>sector = new HashMap<Direction,DistanceToWall>();
		sector.put(Direction.NORTH, new DistanceToWall(1,10));
		sector.put(Direction.EAST, new DistanceToWall(1,10));
		sector.put(Direction.SOUTH, new DistanceToWall(1,10));
		sector.put(Direction.WEST, new DistanceToWall(1,10));
		ghost.setRotation(90);
		ghost.writeWalls(sector, new Coordinate(0,0));
		HashMap<Direction, DistanceToWall>sector1 = new HashMap<Direction,DistanceToWall>();
		sector1.put(Direction.NORTH, new DistanceToWall(1,10));
		sector1.put(Direction.EAST, new DistanceToWall(1,10));
		sector1.put(Direction.SOUTH, new DistanceToWall(1,10));
		sector1.put(Direction.WEST, new DistanceToWall(2,100));
		ghost.setRotation(0);
		ghost.writeWalls(sector1, new Coordinate(0,0));
		assertTrue(ghost.getMaze().read(0, 0, Direction.WEST, true)==1);
	}
	@Test
	public void testWriteWalls2() throws IOException {
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		Game game = new Game();
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator sim = new Simulator(maze,colorMap);
		OwnGhost ghost = new VirtualGhost(game, "jos", sim);
		HashMap<Direction, DistanceToWall>sector1 = new HashMap<Direction,DistanceToWall>();
		sector1.put(Direction.NORTH, new DistanceToWall(1,10));
		sector1.put(Direction.EAST, new DistanceToWall(1,10));
		sector1.put(Direction.SOUTH, new DistanceToWall(1,10));
		sector1.put(Direction.WEST, new DistanceToWall(2,100));
		ghost.setRotation(0);
		ghost.writeWalls(sector1, new Coordinate(0,0));
		assertTrue(ghost.getMaze().read(0, 0, Direction.WEST, true)==2);
	}

}
